import { MessageBox, Message } from 'element-ui'
/**
 * 深拷贝
 * @param {*} obj
 * @returns
 */
export const deepClone = obj => {
    return JSON.parse(JSON.stringify(obj))
}

/**
 *  comfirm 确认框
 * @param {string} text
 * @returns
 */
export const confirm = text => {
    return new Promise((resolve, reject) => {
        MessageBox.confirm(text, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            lockScroll: true
        })
            .then(() => {
                resolve()
            })
            .catch(err => {
                console.log(err)
                Message.info('已取消')
                reject()
            })
            .catch(err => {
                console.log(err)
                // 对错误进行处理
            })
    })
}

export const isNumber = obj => {
    return typeof obj == 'number' && obj.constructor == Number
}
export const isString = str => {
    return typeof str == 'string' && str.constructor == String
}
export const isArray = obj => {
    return typeof obj == 'object' && obj.constructor == Array
}
export const isObject = obj => {
    return typeof obj == 'object' && obj.constructor == Object
}
// 获取 sessionStorage 值
export const getSessionItem = item => {
    return sessionStorage.getItem(item)
}
// 移除
export const removeSessionItem = item => {
    sessionStorage.removeItem(item)
}
export const resData = obj => {
    // Object.keys(obj).forEach((key) => {
    //     if (isString(this.data[key])) {
    //         this.data[key] = ''
    //     } else if (isNumber(this.data[key])) {
    //         this.data[key] = 0
    //     } else if (isArray(this.data[key])) {
    //         this.data[key] = []
    //     } else if (isObject(this.data[key])) {
    //         this.data[key] = {}
    //     }
    // })
}
export default {
    deepClone,
    confirm,
    isNumber,
    isString,
    isArray,
    isObject,
    getSessionItem
}
